<?php

namespace service\impl;

use think\db\BaseQuery;

class BaseImpl
{
    //**************************字段名********************
    protected static string $FIELD_COMMON_ID = 'id';        //公共字段id

    protected static string $FIELD_COMMON_U_ID = 'u_id';

    protected static string $FIELD_COMMON_SUBJECT_ID = 's_id';

    //***************************admin表字段**************
    protected static string $FIELD_ADMIN_USERNAME = 'a_username';   //用户名
    protected static string $FIELD_ADMIN_PASSWORD = 'a_password';   //密码
    protected static string $FIELD_ADMIN_STATUS = 'a_status';   //状态
    protected static string $FIELD_ADMIN_STATUS_REMARK = 'a_status_remark';   //状态描述
    protected static string $FIELD_ADMIN_IS_SUPER = 'a_is_super';   //是否是超管
    protected static string $FIELD_ADMIN_ADD_TIME = 'a_add_time';   //添加时间

    //***************************题目表字段**************
    protected static string $FIELD_SUBJECT_LAN_DIR = 's_lan_dir';   //语向，CE.中译英，EC.英译中
    protected static string $FIELD_SUBJECT_RATE = 's_rate';   //难度系数
    protected static string $FIELD_SUBJECT_TERRITORY_ID = 's_territory_id';   //领域id，1.公司法，可参考配置文件
    protected static string $FIELD_SUBJECT_SOURCE_TEXT = 's_source_text';   //原文
    protected static string $FIELD_SUBJECT_TRANSLATION_TEXT = 's_translation_text';   //译文
    protected static string $FIELD_SUBJECT_FROM = 's_from';   //来源
    protected static string $FIELD_SUBJECT_U_ID = 's_u_id';   //创建者id
    protected static string $FIELD_SUBJECT_U_TYPE = 's_u_type';   //创建者类型，1.管理员。2.用户
    protected static string $FIELD_SUBJECT_ADD_TIME = 's_add_time';   //语向，CE.中译英，EC.英译中

    //************************用户练习配置字段******************************
    protected static string $FIELD_PRACTICE_MODE = 'p_mode'; //练习模式，1.练学同步模式，2.盲练模式，3.收藏复习模式
    protected static string $FIELD_PRACTICE_DIRECTION = 'p_direction'; //练习模式，1.练学同步模式，2.盲练模式，3.收藏复习模式
    protected static string $FIELD_PRACTICE_SUBJECT_COUNT = 'p_subject_count'; //练习模式，1.练学同步模式，2.盲练模式，3.收藏复习模式
    protected static string $FIELD_PRACTICE_TIME = 'p_time'; //练习模式，1.练学同步模式，2.盲练模式，3.收藏复习模式
    protected static string $FIELD_PRACTICE_ADD_TIME = 'p_add_time'; //练习模式，1.练学同步模式，2.盲练模式，3.收藏复习模式

    //******************************练习题目表*****************************
    protected static string $FIELD_PRACTICE_SUBJECT_PRACTICE_ID = 'p_id'; //练习配置id
    protected static string $FIELD_PRACTICE_SUBJECT_TRANSLATION = 'ps_translation'; //自练译文内容
    protected static string $FIELD_PRACTICE_SUBJECT_ADD_TIME = 'ps_add_time'; //添加时间

    //******************************题目扩展表*****************************
    protected static string $FIELD_SUBJECT_EXT_TYPE = 'se_type'; //类型，1.背景知识，2.翻译技巧，3.重点词汇
    protected static string $FIELD_SUBJECT_EXT_TITLE = 'se_title'; //标题
    protected static string $FIELD_SUBJECT_EXT_CONTENT = 'se_content'; //内容
    protected static string $FIELD_SUBJECT_EXT_ADD_TIME = 'se_add_time'; //添加时间

    //******************************题目扩展绑定表*****************************
    protected static string $FIELD_SUBJECT_EXT_BIND_EXT_ID = 'se_id'; //题目扩展id
    protected static string $FIELD_SUBJECT_EXT_BIND_TYPE = 'seb_type'; //题目扩展另见属性
    protected static string $FIELD_SUBJECT_EXT_BIND_ADD_TIME = 'seb_add_time'; //添加时间

    //******************************用户收藏表*****************************
    protected static string $FIELD_USER_COLLECT_ADD_TIME = 'uc_add_time'; //添加时间

    //******************************用户表*****************************
    protected static string $FIELD_USER_USERNAME = 'u_username';
    protected static string $FIELD_USER_PASSWORD = 'u_password';
    protected static string $FIELD_USER_SEX = 'u_sex';
    protected static string $FIELD_USER_PHONE = 'u_phone';
    protected static string $FIELD_USER_EMAIL = 'u_email';
    protected static string $FIELD_USER_BIRTHDAY = 'u_birthday';
    protected static string $FIELD_USER_INTEGRAL = 'u_integral';
    protected static string $FIELD_USER_STATUS = 'u_status';
    protected static string $FIELD_USER_STATUS_REMARK = 'u_status_remark';
    protected static string $FIELD_USER_VIP_EXPIRE_TIME = 'u_vip_expire_time';
    protected static string $FIELD_USER_ADD_TIME = 'u_add_time';

    //*****************************用户练习题目统计表*************************
    protected static string $FIELD_USER_SUBJECT_STATIC_TIMES = 'uss_times';
    protected static string $FIELD_USER_SUBJECT_STATIC_UPDATE_TIME = 'uss_update_time';
    protected static string $FIELD_USER_SUBJECT_STATIC_ADD_TIME = 'uss_add_time';

    //*****************************vip订单表*************************
    protected static string $FIELD_VIP_ORDER_OUT_NUM = 'lvo_out_num';
    protected static string $FIELD_VIP_ORDER_INNER_NUM = 'lvo_inner_num';
    protected static string $FIELD_VIP_ORDER_MONEY = 'lvo_order_money';
    protected static string $FIELD_VIP_ORDER_PAY_MONEY = 'lvo_pay_money';
    protected static string $FIELD_VIP_ORDER_PAY_TIME = 'lvo_pay_time';
    protected static string $FIELD_VIP_ORDER_PAY_STATUS = 'lvo_pay_status';
    protected static string $FIELD_VIP_ORDER_PAY_TYPE = 'lvo_pay_type';
    protected static string $FIELD_VIP_ORDER_ADD_TIME = 'lvo_add_time';
    protected static string $FIELD_VIP_ORDER_EXPIRE_TIME = 'lvo_expire_time';


    //***********************排序方式*************************************
    protected static string $SORT_ID = 'ID';
    protected static string $SORT_RAND = 'Rand';
    protected static string $SORT_PAY_TIME = 'PayTime';

    //***********************排序值*************************************
    protected static string $SORT_VALUE_DESC = 'DESC';
    protected static string $SORT_VALUE_ASC = 'ASC';

    //***********************过滤条件*************************************
    protected static string $FILTER_NAME         = 'Name';                    //名称
    protected static string $FILTER_STATUS       = 'Status';                    //状态
    protected static string $FILTER_ADD_TIME     = 'AddTime';                //时间
    protected static string $FILTER_USER_ID         = 'UserId';                    //用户id
    protected static string $FILTER_MODE         = 'Mode';                    //练习模式
    protected static string $FILTER_DIRECTION         = 'Direction';                    //练习方向
    protected static string $FILTER_PRACTICE_ID         = 'PracticeId';                    //练习配置id
    protected static string $FILTER_SUBJECT_ID         = 'SubjectId';                    //习题id
    protected static string $FILTER_LAN_DIR         = 'LanDir';                    //语向
    protected static string $FILTER_RATE         = 'Rate';                    //难度系数
    protected static string $FILTER_TERRITORY_ID         = 'TerritoryId';                    //领域id
    protected static string $FILTER_SOURCE_TEXT         = 'SourceText';                    //原文
    protected static string $FILTER_USER_TYPE         = 'UserType';                    //创建者类型
    protected static string $FILTER_EMAIL         = 'Email';                    //邮箱
    protected static string $FILTER_PHONE         = 'Phone';                    //手机号
    protected static string $FILTER_INNER_NUM         = 'InnerNum';                    //内部订单号
    protected static string $FILTER_OUT_NUM         = 'OutNum';                    //外部订单号
    protected static string $FILTER_PAY_TIME         = 'PayTime';                    //支付时间
    protected static string $FILTER_PAY_TYPE         = 'PayType';                    //支付方式
    protected static string $FILTER_TYPE         = 'Type';                    //类型
    protected static string $FILTER_NOT_ID_IN         = 'NotIdIn';                    //类型
    protected static string $FILTER_TITLE         = 'Title';                    //类型

    //***********************获取表的结构**********************************

    /**
     * 获取管理员表
     */
    protected function getAdminDb(): BaseQuery
    {
        return db('admin');
    }

    //题目表
    protected function getSubjectDb(): BaseQuery
    {
        return db('subject');
    }

    //用户练习配置
    protected function getPracticeDb(): BaseQuery
    {
        return db('practice');
    }

    //练习题目
    protected function getPracticeSubjectDb(int $userId): BaseQuery
    {
        $ext = $userId % 32;
        return db('practice_subject_' . $ext);
    }

    //题目扩展表
    protected function getSubjectExtDb(): BaseQuery
    {
        return db('subject_ext');
    }

    //题目扩展绑定表
    protected function getSubjectExtBindDb(): BaseQuery
    {
        return db('subject_ext_bind');
    }

    //用户收藏表
    protected function getUserCollectDb(): BaseQuery
    {
        return db('user_collect');
    }

    //用户收藏表
    protected function getUserDb(): BaseQuery
    {
        return db('user');
    }

    //用户练习题目统计表
    protected function getUserSubjectStaticDb(int $userId): BaseQuery
    {
        $ext = $userId % 32;
        return db('user_subject_static_' . $ext);
    }

    //vip订单表
    protected function getVipOrderDb(): BaseQuery
    {
        return db('vip_order');
    }
}